package com.qf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {


    //自动映射，只能将表中字段映射到User对应的属性上
    @Select("select * from t_user where username=#{username}")

    //手动映射
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "id",
                    property = "roles",
                    javaType = List.class,
                    many = @Many(select = "com.qf.mapper.UserMapper.findPermissionByUid")
            )
    })
    User findByUsername(String username);

    @Select("SELECT p.`keyword`\n" +
            "FROM  t_user_role ur,t_role_permission rp,t_permission p\n" +
            "WHERE ur.`role_id`=rp.`role_id` AND rp.`permission_id`=p.`id`\n" +
            "\tAND ur.`user_id`=#{id}")
    List<String> findPermissionByUid(Integer id);

}
